import random
import sys


class ZuoBiao:
    zuoBiaoX = 0  # 横坐标
    zuoBiaoY = 0  # 纵坐标
    ifPlayer = False  # 判断是否为玩家
    ifAi = False  # 判断是否为AI
    ifDaoJu = False  # 判断是否为道具
    ifQiang = False  # 判断是否为墙

    # 我想定义一个可变参数的构造方法，不过后面没有用到
    def __init__(self, *args):
        if len(args) > 0:
            if args[0] == "玩家":
                self.ifPlayer = True
            if args[0] == "AI":
                self.ifAi = True
            if args[0] == "道具":
                self.Daoju = True
    # 构造方法 end

    # 为普通的点赋值,形参类型为changDi
    @staticmethod  # 静态方法
    def puTongFuZhi(self, s):
        s.zuoBiao[s.ciShu].zuoBiaoX = self.game.hengZuoBiao
        s.zuoBiao[s.ciShu].zuoBiaoY = self.game.zongZuoBiao
        s.zuoBiao[s.ciShu].ifAi = False
        s.zuoBiao[s.ciShu].ifPlayer = False
        s.zuoBiao[s.ciShu].ifDaoJu = False
        s.zuoBiao[s.ciShu].ifQiang = False
        return

    # 为普通的点赋值 end

    # 为墙的点赋值,形参类型为changDi
    @staticmethod  # 静态方法
    def qiangFuZhi(self, s):
        s.zuoBiao[s.ciShu].zuoBiaoX = self.game.hengZuoBiao
        s.zuoBiao[s.ciShu].zuoBiaoY = self.game.zongZuoBiao
        s.zuoBiao[s.ciShu].ifAi = False
        s.zuoBiao[s.ciShu].ifPlayer = False
        s.zuoBiao[s.ciShu].ifDaoJu = False
        s.zuoBiao[s.ciShu].ifQiang = True
        return

    # 为墙的点赋值 end

    # 为玩家的点赋值,形参类型为changDi
    @staticmethod  # 静态方法
    def playerFuZhi(self, s):
        s.zuoBiao[s.ciShu].zuoBiaoX = self.game.hengZuoBiao
        s.zuoBiao[s.ciShu].zuoBiaoY = self.game.zongZuoBiao
        s.zuoBiao[s.ciShu].ifAi = False
        s.zuoBiao[s.ciShu].ifPlayer = True
        s.zuoBiao[s.ciShu].ifDaoJu = False
        s.zuoBiao[s.ciShu].ifQiang = False
        return

    # 为玩家的点赋值 end

    # 为AI的点赋值,形参类型为changDi
    @staticmethod  # 静态方法
    def aiFuZhi(self, s):
        s.zuoBiao[s.ciShu].zuoBiaoX = self.game.hengZuoBiao
        s.zuoBiao[s.ciShu].zuoBiaoY = self.game.zongZuoBiao
        s.zuoBiao[s.ciShu].ifAi = True
        s.zuoBiao[s.ciShu].ifPlayer = False
        s.zuoBiao[s.ciShu].ifDaoJu = False
        s.zuoBiao[s.ciShu].ifQiang = False
        return

    # 为AI的点赋值 end

    # 为道具的点赋值,形参类型为changDi
    @staticmethod  # 静态方法
    def daoJuFuZhi(self, s):
        s.zuoBiao[s.ciShu].zuoBiaoX = self.game.hengZuoBiao
        s.zuoBiao[s.ciShu].zuoBiaoY = self.game.zongZuoBiao
        s.zuoBiao[s.ciShu].ifAi = False
        s.zuoBiao[s.ciShu].ifPlayer = False
        s.zuoBiao[s.ciShu].ifDaoJu = True
        s.zuoBiao[s.ciShu].ifQiang = False
        return

    # 为道具的点赋值 end

    # 查看所有点坐标，只在调试程序时使用,形参类型为changDi
    @staticmethod  # 静态方法
    def shuChu(self, s):
        for i in range(0, s.ciShu):
            print("(%s,%s)" % (s.zuoBiao[i].zuoBiaoX, s.zuoBiao[i].zuoBiaoY), end="")
            if s.zuoBiao[i].zuoBiaoX == s.chang - 1:
                print()

    # 查看所有点坐标 end

    # 查看单个点坐标，只在调试程序时使用
    def xianShiZuoBiao(self):
        print("(%s,%s)" % (self.zuoBiaoX, self.zuoBiaoY))
    # 查看单个点坐标，只在调试程序时使用 end


class ChangDi:
    hengZuoBiao = 0  # 横坐标
    zongZuoBiao = 0  # 纵坐标
    hengQiDian = 0  # 横坐标起点
    hengZhongDian = 0  # 横坐标终点
    zongQiDian = 0  # 纵坐标起点
    zongZhongDian = 0  # 纵坐标终点
    xinHengQiDian = 0  # 新横坐标起点
    xinHengZhongDian = 0  # 新横坐标终点
    xinZongQiDian = 0  # 新纵坐标起点
    xinZongZhongDian = 0  # 新纵坐标终点
    chang = 0  # 真实的场景长
    kuan = 0  # 真实的场景宽
    ciShu = 0
    zuoBiao = ZuoBiao()


# 定义玩家类，继承坐标类
class Player(ZuoBiao):
    chaoNengLiCiShu = 3
    def __init__(self):
        super().__init__("玩家")  # 调用父类的构造方法
        self.zuoBiaoX = random.randint(2, chang - 2)
        self.zuoBiaoY = random.randint(2, kuan - 2)
# 定义玩家类，继承坐标类 end

# 定义AI类，继承坐标类
class Ai(ZuoBiao):

    chaoNengLiKuaiPao =False # 当此变量值为True时，AI发动超能力“快跑”
    chaoNengLiBianShen = False # 当此变量值为True时，AI发动超能力“变身”
    bianShenShiJian = 4 # 变身时间持续4回合，实际上是3回合，因为第一次变身毫无意义，当AI动起来后才是真正意义上的第一回合

    def __init__(self, s):
        super().__init__("AI")
        self.zuoBiaoX = random.randint(2, chang - 2)
        self.zuoBiaoY = random.randint(2, kuan - 2)
        self.fangZhiChongHe(s)

    # 防止AI初始坐标与玩家初始坐标重合，形参类型为player
    def fangZhiChongHe(self, s):
        while True:
            if s.zuoBiaoX == self.zuoBiaoX and s.zuoBiaoY == self.zuoBiaoY:
                self.zuoBiaoX = random.randint(2, chang - 2)
                self.zuoBiaoY = random.randint(2, kuan - 2)
            else:
                break
    # 防止AI初始坐标与玩家初始坐标重合 end

# 定义AI类，继承坐标类 end

# 定义道具类，继承坐标类
class DaoJu(ZuoBiao):

    daoJuXianShen = False # 判断道具现身的条件
    xianShenShiJian = 4 # 道具现身的时间
    # aiRenJingZhi = False # 道具矮人静止，用&表示
    aiRenJingZhiShiJian = 3 # 玩家拾起道具后矮人静止的时间
    aiRenJingZhiZhuRen = None #判断道具”矮人静止“被玩家还是被ai拾取
    def __init__(self):
        super().__init__("道具")

    # 防止道具坐标与玩家或AI重合
    def fangZhiChongHe(self, s1,s2):
        while True:
            if s1.zuoBiaoX == self.zuoBiaoX and s1.zuoBiaoY == self.zuoBiaoY or \
                    s2.zuoBiaoX == self.zuoBiaoX and s2.zuoBiaoY == self.zuoBiaoY:
                self.zuoBiaoX = random.randint(2, chang - 2)
                self.zuoBiaoY = random.randint(2, kuan - 2)

            else:
                break
    # 防止道具坐标与玩家或AI重合

# 定义道具类，继承坐标类 end
class GuoCheng:
    game = ChangDi()
    daoJu = DaoJu()

    # 玩家操作
    def caoZuoPlayer(self):
        caoZuo = input("请输入您的操作")
        if caoZuo == "w":
            player.zuoBiaoY -= 2
            if player.zuoBiaoY <= self.game.xinZongQiDian+1:
                player.zuoBiaoY = self.game.xinZongQiDian+1

        elif caoZuo == "s":
            player.zuoBiaoY += 2
            if player.zuoBiaoY >= self.game.xinZongZhongDian - 2:
                player.zuoBiaoY = self.game.xinZongZhongDian - 2

        elif caoZuo == "a":
            player.zuoBiaoX -= 2
            if player.zuoBiaoX <= self.game.xinHengQiDian+1:
                player.zuoBiaoX = self.game.xinHengQiDian+1

        elif caoZuo == "d":
            player.zuoBiaoX += 2
            if player.zuoBiaoX >= self.game.xinHengZhongDian - 2:
                player.zuoBiaoX = self.game.xinHengZhongDian - 2

        elif caoZuo =="x":
            self.playerChaoNengLiX();
            if player.chaoNengLiCiShu>0:
                player.chaoNengLiCiShu -= 1
                print("巨人发动超能力——\"横向移墙\"！,超能力剩余次数为%d")
            else:
                print("超能力次数已用尽，无法继续使用")
                self.caoZuoPlayer()


        elif caoZuo =="y":
            self.playerChaoNengLiY();
            if player.chaoNengLiCiShu>0:
                player.chaoNengLiCiShu -= 1
                print("巨人发动超能力——\"纵向移墙\"！,超能力剩余次数为%d")
            else:
                print("超能力次数已用尽，无法继续使用")
                self.caoZuoPlayer()


        elif caoZuo != "r":
            print("输入错误，请重新输入")
            self.caoZuoPlayer()
    # 玩家操作 end

    # 左右方向的超能力
    def playerChaoNengLiX(self):

        if ai.zuoBiaoX <= player.zuoBiaoX:
            self.game.xinHengZhongDian = player.zuoBiaoX+2

        elif ai.zuoBiaoX > player.zuoBiaoX:
            self.game.xinHengQiDian = player.zuoBiaoX-1
    # 左右方向的超能力 end

    # 上下方向的超能力
    def playerChaoNengLiY(self):

        if ai.zuoBiaoY <= player.zuoBiaoY:
            self.game.xinZongZhongDian = player.zuoBiaoY+2

        elif ai.zuoBiaoY > player.zuoBiaoY:
            self.game.xinZongQiDian = player.zuoBiaoY-1
    # 上下方向的超能力 end

    # AI超能力“快跑”
    def aiChaoNengLiKuaiPao(self):

        fangXiang = random.choice(["x","y"]) # 当变量fangXiang为x时发动横向超能力，为y时发动纵向超能力
        ai.chaoNengLiKuaiPao = True
        if fangXiang == "x":
            if ai.zuoBiaoX < player.zuoBiaoX:
                ai.zuoBiaoX -= 4
                if ai.zuoBiaoX <= self.game.xinHengQiDian+1:
                    ai.zuoBiaoX = self.game.xinHengQiDian+1

            elif ai.zuoBiaoX == player.zuoBiaoX:
                if random.randint(1,2) == 1:
                    ai.zuoBiaoX -= 4
                    if ai.zuoBiaoX <= self.game.xinHengQiDian + 1:
                        ai.zuoBiaoX = self.game.xinHengQiDian + 1
                else:
                    ai.zuoBiaoX += 4
                    if ai.zuoBiaoX >= self.game.xinHengZhongDian - 2:
                        ai.zuoBiaoX = self.game.xinHengZhongDian - 2

            else:
                ai.zuoBiaoX += 4
                if ai.zuoBiaoX > self.game.xinHengZhongDian-2:
                    ai.zuoBiaoX = self.game.xinHengZhongDian-2
        else :
            if ai.zuoBiaoY < player.zuoBiaoY:
                ai.zuoBiaoY -= 4
                if ai.zuoBiaoY <= self.game.xinZongQiDian+1:
                    ai.zuoBiaoY = self.game.xinZongQiDian+1

            elif ai.zuoBiaoY < player.zuoBiaoY:
                if random.randint(1,2) == 1:
                    ai.zuoBiaoY -= 4
                    if ai.zuoBiaoY <= self.game.xinZongQiDian + 1:
                        ai.zuoBiaoY = self.game.xinZongQiDian + 1
                else:
                    ai.zuoBiaoY += 4
                    if ai.zuoBiaoY >= self.game.xinZongZhongDian - 2:
                        ai.zuoBiaoY = self.game.xinZongZhongDian - 2

            else:
                ai.zuoBiaoY += 4
                if ai.zuoBiaoY >= self.game.xinZongZhongDian-2:
                    ai.zuoBiaoY = self.game.xinZongZhongDian-2
        print("矮人发动超能力--\"快跑\"！")
    # AI超能力“快跑” end

    # AI超能力"变身"
    def aiChaoNengLiBianShen(self,faShengXunHuan):
        # AI超能力"变身"的实现过程
        if faShengXunHuan == False:
            if random.randint(1, 4) == 1 and ai.chaoNengLiBianShen == False and \
                    ai.zuoBiaoX != player.zuoBiaoX and player.zuoBiaoY != ai.zuoBiaoY:  # 使AI有20%的概率发动超能力"变身",且不能在已经变身的时间内再次发动变身
                print("矮人化作深渊之主马努斯,持续3回合")
                ai.chaoNengLiBianShen = True
            if ai.chaoNengLiBianShen == True and ai.bianShenShiJian > 0:
                if ai.bianShenShiJian > 1:
                    print("深渊之主马努斯还剩%s回合变回矮人,不要被他碰到！" % str(ai.bianShenShiJian - 1))
                ai.bianShenShiJian -= 1
                if ai.bianShenShiJian <= 0:
                    ai.chaoNengLiBianShen = False
                    ai.bianShenShiJian = 4
        # AI超能力"变身"的实现过程 end
    # AI超能力"变身" end

    # AI操作
    def caoZuoAi(self):

        caoZuo = list()
        caoZuo.append(self.yaoHao())
        faShengXunHuan = False

        while True:

            self.aiChaoNengLiBianShen(faShengXunHuan)

            if self.daoJu.aiRenJingZhiZhuRen == "player":
                self.daoJu.aiRenJingZhiShiJian -= 1
                if self.daoJu.aiRenJingZhiShiJian <= 0:
                    self.daoJu.daoJuXianShen = False
                    self.daoJu.aiRenJingZhiZhuRen = None
                    self.daoJu.aiRenJingZhiShiJian = 4
                break

            if caoZuo[-1] == "w":
                if ai.zuoBiaoY <= self.game.xinZongQiDian + 1:
                    caoZuo.append(self.baiZhiSuanFa(caoZuo))
                else:
                    if random.randint(1,4) == 1: # 使AI有20%的概率发动超能力"快跑"
                        self.aiChaoNengLiKuaiPao()
                        ai.chaoNengLiKuaiPao=False
                    else:
                        ai.zuoBiaoY -= 1
                    break

            if caoZuo[-1] == "s":
                if ai.zuoBiaoX >= self.game.xinHengZhongDian - 2:
                    caoZuo.append(self.baiZhiSuanFa(caoZuo))
                else:
                    if random.randint(1,4) == 1:
                        self.aiChaoNengLiKuaiPao()
                        ai.chaoNengLiKuaiPao = False
                    else:
                        ai.zuoBiaoY += 1
                    break

            if caoZuo[-1] == "a":
                if ai.zuoBiaoX <= self.game.xinHengQiDian + 1:
                    caoZuo.append(self.baiZhiSuanFa(caoZuo))
                else:
                    if random.randint(1,4) == 1:
                        self.aiChaoNengLiKuaiPao()
                        ai.chaoNengLiKuaiPao = False
                    else:
                        ai.zuoBiaoX -= 1
                    break

            if caoZuo[-1] == "d":
                if ai.zuoBiaoX >= self.game.xinHengZhongDian - 2:
                    caoZuo.append(self.baiZhiSuanFa(caoZuo))
                    faShengXunHuan = True
                else:
                    if random.randint(1,4) == 1:
                        self.aiChaoNengLiKuaiPao()
                        ai.chaoNengLiKuaiPao = False
                    else:
                        ai.zuoBiaoX += 1
                    break

    # AI操作 end

    # 柏智算法：防止AI卡进墙(写这段代码主要是利用上节课学过的知识)
    def baiZhiSuanFa(self, caoZuo):
        list = ["w", "s", "a", "d"]
        for cXiaBiao in range(len(caoZuo)):
            for lZhi in list:
                if caoZuo[cXiaBiao] == lZhi:
                    list.remove(lZhi)

        xinRandom = random.choice(list)
        return xinRandom
    # 柏智算法：防止AI卡进墙 end

    # 摇号
    def yaoHao(self):
        x = random.choice(["w", "s", "a", "d"])
        return x

    # 摇号 end

    # 构建场地
    def gouJianChangDi(self):
        for self.game.zongZuoBiao in range(self.game.zongQiDian, self.game.zongZhongDian):  # 建立纵轴
            for self.game.hengZuoBiao in range(self.game.hengQiDian, self.game.hengZhongDian):  # 建立横轴

                # 建立墙
                if self.game.hengZuoBiao == self.game.xinHengQiDian or self.game.hengZuoBiao == self.game.xinHengZhongDian - 1 or \
                        self.game.zongZuoBiao == self.game.xinZongQiDian or self.game.zongZuoBiao == self.game.xinZongZhongDian - 1:
                    if self.game.hengZuoBiao < self.game.xinHengQiDian or self.game.hengZuoBiao > self.game.xinHengZhongDian-1 or \
                        self.game.zongZuoBiao < self.game.xinZongQiDian or self.game.zongZuoBiao > self.game.xinZongZhongDian-1:
                        print(" \t",end="")
                    else:
                        print("*\t", end="")
                    ZuoBiao.qiangFuZhi(self, self.game)
                    self.game.ciShu += 1
                # 建立墙 end

                # 活动范围
                else:
                    if player.zuoBiaoX == self.game.hengZuoBiao and player.zuoBiaoY == self.game.zongZuoBiao:
                        print("@\t", end="")
                        ZuoBiao.playerFuZhi(self, self.game)
                    elif ai.zuoBiaoX == self.game.hengZuoBiao and ai.zuoBiaoY == self.game.zongZuoBiao:
                        if ai.chaoNengLiBianShen == False:
                            print("#\t", end="")
                        else:
                            print("!\t",end="")
                        ZuoBiao.aiFuZhi(self, self.game)

                    elif self.daoJu.daoJuXianShen == True:
                        if self.daoJu.zuoBiaoX == self.game.hengZuoBiao and self.daoJu.zuoBiaoY == self.game.zongZuoBiao:
                            print("&\t",end="")
                            ZuoBiao.daoJuFuZhi(self, self.game)
                        else:
                            print(" \t", end="")
                            ZuoBiao.puTongFuZhi(self, self.game)

                    else:
                        print(" \t", end="")
                        ZuoBiao.puTongFuZhi(self, self.game)
                    self.game.ciShu += 1
                # 活动范围 end
            print()
        return
    # 构建场地 end

    # 成功场景,最后一次出现的场景
    def chengGongChangJing(self):
        for self.game.zongZuoBiao in range(self.game.zongQiDian, self.game.zongZhongDian):  # 建立纵轴
            for self.game.hengZuoBiao in range(self.game.hengQiDian, self.game.hengZhongDian):  # 建立横轴

                # 建立墙
                if self.game.hengZuoBiao == self.game.xinHengQiDian or self.game.hengZuoBiao == self.game.xinHengZhongDian - 1 or \
                        self.game.zongZuoBiao == self.game.xinZongQiDian or self.game.zongZuoBiao == self.game.xinZongZhongDian - 1:
                    if self.game.hengZuoBiao < self.game.xinHengQiDian or self.game.hengZuoBiao > self.game.xinHengZhongDian-1 or \
                        self.game.zongZuoBiao < self.game.xinZongQiDian or self.game.zongZuoBiao > self.game.xinZongZhongDian-1:
                        print(" \t",end="")
                    else:
                        print("*\t", end="")
                    self.game.ciShu += 1
                # 建立墙 end

                # 活动范围
                else:
                    if player.zuoBiaoX == self.game.hengZuoBiao and player.zuoBiaoY == self.game.zongZuoBiao:
                        print("@\t", end="")
                    else:
                        print(" \t", end="")
                    self.game.ciShu += 1
                # 活动范围 end
            print()
        return
    # 成功场景 end

    # 失败场景，被变身后的AI抓住后生成的场景
    def shiBaiChangJing(self):
        for self.game.zongZuoBiao in range(self.game.zongQiDian, self.game.zongZhongDian):  # 建立纵轴
            for self.game.hengZuoBiao in range(self.game.hengQiDian, self.game.hengZhongDian):  # 建立横轴

                # 建立墙
                if self.game.hengZuoBiao == self.game.xinHengQiDian or self.game.hengZuoBiao == self.game.xinHengZhongDian - 1 or \
                        self.game.zongZuoBiao == self.game.xinZongQiDian or self.game.zongZuoBiao == self.game.xinZongZhongDian - 1:
                    if self.game.hengZuoBiao < self.game.xinHengQiDian or self.game.hengZuoBiao > self.game.xinHengZhongDian-1 or \
                        self.game.zongZuoBiao < self.game.xinZongQiDian or self.game.zongZuoBiao > self.game.xinZongZhongDian-1:
                        print(" \t",end="")
                    else:
                        print("*\t", end="")
                    self.game.ciShu += 1
                # 建立墙 end

                # 活动范围
                else:
                    if player.zuoBiaoX == self.game.hengZuoBiao and player.zuoBiaoY == self.game.zongZuoBiao:
                        print("@\t", end="")
                    else:
                        print(" \t", end="")
                    self.game.ciShu += 1
                # 活动范围 end
            print()
        return
    # 失败场景 end

    # 道具相关的操作
    def daoJuChuXian(self):
        if self.daoJu.daoJuXianShen == False:
            if random.randint(1, 2) == 1:
                self.daoJu.daoJuXianShen = True
                self.daoJu.zuoBiaoX = random.randint(self.game.xinHengQiDian+2, self.game.xinHengZhongDian-2)
                self.daoJu.zuoBiaoY = random.randint(self.game.xinZongQiDian+2,self.game.xinZongZhongDian-2)
                while True:
                    if (ai.zuoBiaoX == self.daoJu.zuoBiaoX and ai.zuoBiaoY == self.daoJu.zuoBiaoY) or\
                            (player.zuoBiaoX == self.daoJu.zuoBiaoX and player.zuoBiaoY == self.daoJu.zuoBiaoY):
                        self.daoJu.zuoBiaoX = random.randint(self.game.xinHengQiDian + 2,
                                                             self.game.xinHengZhongDian - 2)
                        self.daoJu.zuoBiaoY = random.randint(self.game.xinZongQiDian + 2,
                                                             self.game.xinZongZhongDian - 2)
                    else:
                        break
        if self.daoJu.daoJuXianShen == True :
            if self.daoJu.xianShenShiJian == 4:
                print("道具“矮人静止”出现！持续3回合!")
            else:
                print("还有%d回合道具消失" % (self.daoJu.xianShenShiJian - 1))
            self.daoJu.xianShenShiJian -= 1
            if self.daoJu.xianShenShiJian <= 0:
                self.daoJu.xianShenShiJian = 4
                self.daoJu.daoJuXianShen = False
        self.daoJuShiQu()

    def daoJuShiQu(self):


        if player.zuoBiaoX == self.daoJu.zuoBiaoX and player.zuoBiaoY == self.daoJu.zuoBiaoY:
            print("巨人拾取道具”矮人静止“，矮人静止3回合")
            self.daoJu.aiRenJingZhiZhuRen = "player"
            self.daoJu.daoJuXianShen = False
            self.daoJu.xianShenShiJian = 4
        if ai.zuoBiaoX == self.daoJu.zuoBiaoX and ai.zuoBiaoY == self.daoJu.zuoBiaoY:
            print("矮人拾取道具“矮人静止“，使道具无效化")
            self.daoJu.daoJuXianShen = False
            self.daoJu.xianShenShiJian = 4

    # 游戏过程
    def youXiGuoCheng(self,):
        global chang

        global kuan

        self.game.chang = chang
        self.game.kuan = kuan
        self.game.hengZhongDian = self.game.chang
        self.game.zongZhongDian = self.game.kuan
        self.game.xinHengQiDian = self.game.hengQiDian
        self.game.xinHengZhongDian = self.game.hengZhongDian
        self.game.xinZongQiDian = self.game.zongQiDian
        self.game.xinZongZhongDian = self.game.zongZhongDian
        self.game.zuoBiao = [ZuoBiao() for i in range(0, (self.game.zongZhongDian - self.game.zongQiDian) * (
                    self.game.hengZhongDian - self.game.hengQiDian) + 1)]

        while True:
            if ai.chaoNengLiBianShen == False and ai.zuoBiaoX==player.zuoBiaoX and player.zuoBiaoY==ai.zuoBiaoY:
                self.chengGongChangJing()
                print("就在你抓住无名的矮人那一瞬间，矮人化作深渊之主马努斯")
                print("他将你吞噬")
                print("你在一片地下废墟中醒来，这里的道路错综复杂，并且没有“时间”的概念，周围布满巨人的骸骨")
                print("看来有无数像你一样，为了夺取余火的巨人来到这里")
                print("这里是巨人墓地！墓地的领主正是四王之一——最初的死者尼特！")
                print("感谢游玩《无名矮人的余火》，请期待续作——《死者尼特的墓王剑》")
                break
            elif ai.chaoNengLiBianShen == True and ai.zuoBiaoX==player.zuoBiaoX and player.zuoBiaoY==ai.zuoBiaoY:
                self.shiBaiChangJing()
                print("化为深渊之主马努斯的矮人吞噬了你，游戏失败")
                break



            self.game.ciShu = 0
            self.gouJianChangDi()


            self.caoZuoPlayer()
            caoZuo = self.yaoHao()
            self.caoZuoAi()
            self.daoJuChuXian()
    # 游戏过程 end


def youXiJuQing():
    print("你是巨人王尤姆手下的战士吧？")
    print("啊哈哈哈，那就让我来告诉你，你的使命吧！")
    print("世界诞生之初，不朽的古龙盘踞在世界各地，人类只得在古龙的压迫下苟延残喘")
    print("直到一天，初火诞生了")
    print("生与死、冷与暖、光与暗")
    print("最重要的是：它带给了人类与古龙抗争的机会")
    print("无鳞的白龙希斯背叛了古龙，它告诉人类古龙的不朽在于它们的鳞片，而雷电是鳞片唯一的弱点")
    print("乌薪王葛温向巨龙射出雷枪，摧毁古龙的鳞片")
    print("最初的死者尼特释放死亡瘴气，夺走古龙的生命")
    print("无名的矮人化作深渊之主马努斯，吞噬古龙的灵魂")
    print("混沌魔女伊扎里斯施展混沌火焰，燃烧古龙的栖息之地")
    print("在四王的领导下，人类将古龙屠杀殆尽，四王与无名的矮人各分得了一部分初火的余烬，火之时代开启了！")
    print("而火，是会熄灭的")
    print("初火熄灭之时，人类将失去意识，变成不死的化身")
    print("为了延续初火，乌薪王葛温以灵魂作为薪柴，燃烧了自己，成为初始的薪王")
    print("最初的死者尼特和混沌魔女伊扎里斯隐居在自己的领地")
    print("没有人知道他们领地的入口，没有人知道他们在做些什么")
    print("现在，乌薪王葛温的灵魂燃烧殆尽，世界之火又将熄灭")
    print("不能成为薪王的巨人王尤姆燃烧自己，让世界得以短暂的延续")
    print("而在你面前的，就是那无名矮人的领地，只有得到它手里的初火余烬，才能再次点燃初火！")
    print("去吧，不死的英雄啊！趁着巨人王尤姆的身躯还能燃烧，你必须夺走矮人手中的余火！")
    ("按回车键继续...") # 让程序暂停一下下
    return

def caoZuoZhiNan():
    print("\n")
    print("“@”代表巨人,“#”代表矮人，“&”代表道具")
    print("矮人发动超能力变身后会变成“！”，此时不要碰到矮人，否则游戏失败")
    print("输入w,s,a,d控制上下左右行走")
    print("输入r静止不动")
    print("输入x发动超能力——横向移墙")
    print("输入y发动超能力——纵向移墙")
    return

def gameMain():
    youXiJuQing()
    caoZuoZhiNan()

    global chang
    global kuan
    global player
    global ai
    chang = int(input("请输入场景的长(越大越好玩，推荐为20)")) + 2
    kuan = int(input("请输入场景的宽(越大越好玩，推荐为20")) + 2
    player = Player()
    ai = Ai(player)

    x = GuoCheng()
    x.youXiGuoCheng()


chang = None
kuan = None
global player
player = None
global ai
ai = None




if __name__ == "__main__":

    gameMain()

